home *** CD-ROM | disk | FTP | other *** search
- Path: news.primenet.com!not-for-mail
- From: kj7bg@primenet.com (Bob White)
- Newsgroups: comp.lang.c++
- Subject: Re: HELP Borland C++ 5.0 pointer problem
- Date: 12 Apr 1996 13:17:00 -0700
- Organization: Primenet Services for the Internet
- Sender: root@primenet.com
- Message-ID: <4kmdns$7b7@nnrp1.news.primenet.com>
- References: <4klke8$7mb@dub-news-svc-2.compuserve.com>
- X-Posted-By: ip201.boi.primenet.com
- X-Newsreader: WinVN 0.99.7
- MIME-Version: 1.0
- Content-Type: Text/Plain; charset=US-ASCII
-
- It worked in Win16, because you were LUCKY! The "buffer" character array is
- allocated on the local stack when the function is entered and deleted when the
- function returns. Hence, you are returning a pointer to a variable which has
- been deleted. You could solve this by getting a new area using "new" or
- "malloc" and returning the ptr to it. You would then have to delete or free
- it when you were done. Hope that helps.
-
- Bob
-
-
- In article <4klke8$7mb@dub-news-svc-2.compuserve.com>,
- 100660.2242@compuserve.com says...
- >
- >Could you please tell me why the function below compiles and operates
- >correctly under win16 but not win32 ?
- >
- > char* test_function(char *in_data) {
- >
- > char buffer[20];
- > strcpy(buffer, in_data); // copy in_data to buffer
- > in_data = buffer; // set pointer to buffer
- >
- > return(in_data);
- >
- > } // end test_function function
- >
- >Regards
- >
- >Andy Graham
- >
-
-